package controller;

import core.BaseServlet;
import service.MemberService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 运营管理模块Servlet
 */
@WebServlet(name = "MemberServlet", urlPatterns = "/member")
public class MemberServlet extends BaseServlet {

    private MemberService memberService = new MemberService();

    /**
     * 会员管理页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void memberManagePage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/operationManage/memberManage/memberManage.jsp").forward(request, response);
    }

    /**
     * （按条件）展示所有会员的方法
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void listMember(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        memberService.listMember(request, response);
    }

    /**
     * 软删除
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        memberService.delete(request, response);
    }

    /**
     * 真删除
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void realDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        memberService.realDelete(request, response);
    }

    /**
     * 恢复会员
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void restore(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        memberService.restore(request, response);
    }

    /**
     * 回收站页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void memberDeletedManagePage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/operationManage/memberManage/memberDeletedManage.jsp").forward(request, response);
    }

    /**
     * 软删除
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void getAllMemberRole(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        memberService.getAllMemberRole(request, response);
    }

    /**
     * 编辑员工页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void editMemberPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        memberService.getEditMember(request , response);
        request.getRequestDispatcher("/WEB-INF/pages/operationManage/memberManage/memberEdit.jsp").forward(request,response);
    }

    /**
     * 编辑会员
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void edit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        memberService.edit(request, response);
    }

    /**
     * 获取当前编辑的会员对象
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void getEditMember(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        memberService.getEditMember(request, response);
    }

    /**
     * 根据电话号码发送验证码
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void sendCodeByMemberPhone(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        memberService.sendCodeByMemberPhone(request, response);
    }


    /**
     * 根据验证码获取密码
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void resetPasswordByForgetWorkerPhone(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        memberService.resetPasswordByForgetWorkerPhone(request, response);
    }


    ///**
    // * 登录
    // * @param request
    // * @param response
    // * @throws ServletException
    // * @throws IOException
    // */
    //public void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //    memberService.login(request, response);
    //}
}
